package org.adorsys.aderp.aderplogin.client.hessian;

import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URL;

import org.adorsys.aderp.aderplogin.client.common.TokenProvider;

import com.caucho.hessian.client.HessianProxyFactory;
import com.caucho.hessian.io.HessianRemoteObject;

public class HessianTokenInCookieProxyFactory extends HessianProxyFactory {

	private TokenProvider tokenProvider;
	
	private String cookieTokenName;

	@Override
    public Object create(Class api, String urlName, ClassLoader loader)
            throws MalformedURLException {
        URL url = new URL(urlName);

        HessianTokenInCookieProxy handler = new HessianTokenInCookieProxy(this, url);
        handler.setCookieTokenName(cookieTokenName);
        handler.setTokenProvider(tokenProvider);

        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                new Class[]{api, HessianRemoteObject.class}, handler);
    }

	public void setTokenProvider(TokenProvider tokenProvider) {
		this.tokenProvider = tokenProvider;
	}

	public void setCookieTokenName(String cookieTokenName) {
		this.cookieTokenName = cookieTokenName;
	}
}
